package com.chenwenxuan.sync.ui.editor;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import com.chenwenxuan.sync.console.model.TaskCatalog;
import com.chenwenxuan.sync.ui.editor.desginer._TaskCatalogPanel;


public class TaskCatalogEditor extends FormEditor {

	private static final long serialVersionUID = -1507605066296701568L;

	private TaskCatalog input;

	private _TaskCatalogPanel inner;
	
	public TaskCatalogEditor() {
		super();
	}
	

	@Override
	protected void initUI() {
		super.initUI();
		inner = new _TaskCatalogPanel();
		getFormContent().add(inner, BorderLayout.CENTER);
		//inner.setBackground(Color.white);
		inner.getTxtTaskCatalogId().setEditable(false);
		inner.getTxtTaskCatalogName().setEditable(false);
	}
	
	@Override
	protected void linkEvent() {
		super.linkEvent();
		getBtnModify().addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				inner.getTxtTaskCatalogName().setEditable(true);
			}
		});
		getBtnCancel().addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				setInput(input);
				
			}
		});
	}
	

	@Override
	public Object getOutput() {
		return input;
	}

	@Override
	public String getDisplayName() {
		return input.getTaskCatalogName();
	}

	@Override
	public void setInput(Object input) {
		this.input = (TaskCatalog) input;
		
		inner.getTxtTaskCatalogId().setText(this.input.getTaskCatalogId() + "");
		inner.getTxtTaskCatalogName().setText(this.input.getTaskCatalogName());
		
	}

	@Override
	public boolean isOpenedFor(Object input) {
		
		if ( input == null ) return false;
		if ( !(input instanceof TaskCatalog) ) return false;
		
		TaskCatalog toBeOpened = (TaskCatalog) input;
		
		if ( this.input.getTaskCatalogId() == toBeOpened.getTaskCatalogId() )
			return true;
		
		return false;
		
	}

}
